package com.fengdi.controller;

import com.fengdi.pojo.Article;
import com.fengdi.pojo.PageBean;
import com.fengdi.pojo.Result;
import com.fengdi.service.serviceInterface.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article")
@SuppressWarnings("all")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * @author FengDi
     * @Description  新增文章
     * @param article: 文章详细信息
     * @return 创建结果
     * */
    @PostMapping("")
    public Result<?> addArticle(@RequestBody Article article) {
        return this.articleService.addArticle(article);
    }

    /**
     * @author FengDi
     * @Description 获取文章列表
     * @param pageNum 当前页码
     * @param pageSize 页面大小
     * @param categoryId 所属分类
     * @param state 发布状态
     * @return 分页数据
     * */
    @GetMapping
    public Result<PageBean<Article>> getList(
        Integer pageNum,
        Integer pageSize,
        @RequestParam(required = false) Integer categoryId,
        @RequestParam(required = false) String state
    ) {
        return this.articleService.getArticleList(pageNum, pageSize, categoryId, state);
    }

    /**
     * @author FengDi
     * @Description 获取文章详情
     * @param id 文章Id
     * @return 文章详情数据
     * */
    @GetMapping("/detail")
    public Result<Article> getArticleInfo(Integer id) {
        return this.articleService.getArticleInfo(id);
    }

    /**
     * @author FengDi
     * @Description 更新文章详情
     * @param article 新的文章详情数据
     * @return
     * */
    @PutMapping
    public Result<?> updateArticle(@RequestBody Article article) {
        return this.articleService.updateArticle(article);
    }

    /**
     * @author FengDi
     * @Description 删除文章
     * @param id 删除文章的id
     * @return 删除结果
     * */
    @DeleteMapping
    public Result<?> deleteArticle(Integer id) {
        return this.articleService.deleteArticle(id);
    }
}
